package com.hkzhao.shixun.component;

import com.hkzhao.shixun.mbg.mapper.ActivityMapper;
import com.hkzhao.shixun.mbg.mapper.StatMapper;
import com.hkzhao.shixun.mbg.model.Activity;
import com.hkzhao.shixun.mbg.model.ActivityExample;
import com.hkzhao.shixun.service.AdminService;
import com.hkzhao.shixun.service.DrawsLotteryService;
import com.hkzhao.shixun.service.StatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * <h3>j2ee</h3>
 * <p>每天的corn定时清除抽奖次数</p>
 *
 * @author : hkzhao
 * @date : 2020-06-07 22:38
 **/
@Component
public class ScheduledLottery {
    @Autowired
    private DrawsLotteryService drawsLotteryService;
    @Value("${redis.key.LotteryRecordHeaderEveryDay}")
    private String LotteryRecordHeaderByDay;

    //每天执行一遍 林晨12点
    @Scheduled(cron = "0 0 0 * * ?")
    public void delteEveryDayRecord(){
        drawsLotteryService.deleteLotteryNumsEveryDay(LotteryRecordHeaderByDay);
    }
    @Autowired(required=false)
    private ActivityMapper activityMapper;
    @Autowired
    private StatService statService;
    @Scheduled(cron = "59 59 23 * * ?")
    public void logtomysql()
    {
        Date t=new Date();
        ActivityExample activityExample=new ActivityExample();
        ActivityExample.Criteria r1=activityExample.createCriteria();r1.andActivityidIsNotNull();
        List<Activity> la=activityMapper.selectByExample(activityExample);
        for (Activity x:la)
            statService.transfertomysql(x.getActivityid());
    }
}
